using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Eve.API
{
    /// <summary>
    /// Represents an entry in the wallet transactions log.
    /// </summary>
    /// <remarks>
    /// <para>The values in the <b>WalletTransaction</b> class are similar to the data in the Wallet\Transactions view.</para>
    /// <para>Each entry is identified by a transaction id that uniquely identifies the transaction, and can be used when walking
    /// through the list of transactions.</para>
    /// <para>Transactions are generated when items are bought or sold on the in-game market.</para>
    /// </remarks>
    [Serializable]
    public class WalletTransaction
    {
        private DateTime date;
        private int transactionId;
        private int quantity;
        private NameId type = new NameId();
        private double price;
        private NameId client = new NameId();
        private NameId character = new NameId();
        private NameId station = new NameId();
        private string transactionType;

        /// <summary>
        /// Gets the date and time at which the transaction occurred.
        /// </summary>
        /// <value>
        /// The Eve date and time at which the transaction occurred.
        /// </value>
        /// <remarks>
        /// <note type="note">This time is not localized.  It represents game time.</note>
        /// </remarks>
        public DateTime DateTime
        {
            get { return date; }
        }
        /// <summary>
        /// Gets the transaction identifier for the transaction.
        /// </summary>
        /// <value>
        /// The transaction identifier for the transaction.
        /// </value>
        public int TransactionId
        {
            get { return transactionId; }
        }
        /// <summary>
        /// Gets the number of units of the item bought or sold.
        /// </summary>
        /// <value>
        /// The number of units of the item bought or sold.
        /// </value>
        /// <remarks>
        /// The total cost/revenue of the transaction is <b>Quantity</b> * <b>Price</b>.
        /// </remarks>
        public int Quantity
        {
            get { return quantity; }
        }
        /// <summary>
        /// Gets the name and type identifier of the item that was bought or sold.
        /// </summary>
        /// <value>
        /// The name and type identifier of the item that was bought or sold.
        /// </value>
        /// <remarks>
        /// The type identifier returned by this property can be used with the <b>Eve.Data</b> class library to retrieve
        /// detailed information about the item.
        /// </remarks>
        public NameId Type
        {
            get { return type; }
        }
        /// <summary>
        /// Gets the price at which the item was bought or sold.
        /// </summary>
        /// <value>
        /// The price at which the item was bought or sold.
        /// </value>
        /// <remarks>
        /// The total cost/revenue of the transaction is <b>Quantity</b> * <b>Price</b>.
        /// </remarks>
        public double Price
        {
            get { return price; }
        }
        /// <summary>
        /// Gets the name and identifier of the transaction client.
        /// </summary>
        /// <value>
        /// The name and Eve internal identifier of the transaction client.
        /// </value>
        public NameId Client
        {
            get { return client; }
        }
        /// <summary>
        /// Gets the name and identifier of the transaction character.
        /// </summary>
        /// <value>
        /// The name and Eve internal identifier of the transaction character.
        /// </value>
        public NameId Character
        {
            get { return character; }
        }
        /// <summary>
        /// Gets the name and identifier of the station where the transaction occurred.
        /// </summary>
        /// <value>
        /// The name and Eve internal identifier of the station where the transaction occurred.
        /// </value>
        /// <remarks>
        /// The identifier returned by this property can be used with the <b>Eve.Data</b> class library to retrieve
        /// detailed information about the station.
        /// </remarks>
        public NameId Station
        {
            get { return station; }
        }
        /// <summary>
        /// Gets the type of transaction.
        /// </summary>
        /// <value>
        /// The type of transaction, either <b>buy</b> or <b>sell</b>.
        /// </value>
        public string TransactionType
        {
            get { return transactionType; }
        }

        internal WalletTransaction(XmlElement wt)
        {
            date = DateTime.Parse(wt.Attributes["transactionDateTime"].Value);
            transactionId = int.Parse(wt.Attributes["transactionID"].Value);
            quantity = int.Parse(wt.Attributes["quantity"].Value);
            type.Name = wt.Attributes["typeName"].Value;
            type.Id = int.Parse(wt.Attributes["typeID"].Value);
            price = double.Parse(wt.Attributes["price"].Value);
            client.Name = wt.Attributes["clientName"].Value;
            client.Id = int.Parse(wt.Attributes["clientID"].Value);
            character.Name = wt.Attributes["characterName"].Value;
            character.Id = int.Parse(wt.Attributes["characterID"].Value);
            station.Name = wt.Attributes["stationName"].Value;
            station.Id = int.Parse(wt.Attributes["stationID"].Value);
            transactionType = wt.Attributes["transactionType"].Value;
        }
    }
}
